package cn.cs.service.impl;

import cn.cs.client.CsMenuClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.CsMenu;
import cn.cs.service.CsMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CsMenuServiceImpl implements CsMenuService {

    @Resource
    private CsMenuClient menuClient;

    public CsMenu getCsMenuById(Long id) throws Exception {
        return menuClient.getCsMenuById(id);
    }


    public List<CsMenu> getCsMenuByRoleName(String roleName){
        return menuClient.getCsMenuByRoleName(roleName);
    }

    public List<CsMenu> getMenuTree(List<String> authoritiesList, List<String> ids){
        return menuClient.getMenuTree(authoritiesList, ids);
    }

    public List<CsMenu> getMenuList(String pId, List<String> authoritiesList, List<String> ids){
        return menuClient.getMenuList(pId, authoritiesList, ids);
    }

    public List<CsMenu> getMenuByRoleId(String id){
        return menuClient.getMenuByRoleId(id);
    }

    public List<CsMenu> getCsMenuListByMap(Map<String, Object> param){
        return menuClient.getCsMenuListByMap(param);
    }

    public List<CsMenu> getAllMenu() {
        return menuClient.getCsMenuListByMap(new HashMap<>());
    }

    public Integer getCsMenuCountByMap(Map<String, Object> param) throws Exception {
        return menuClient.getCsMenuCountByMap(param);
    }

    public Integer addCsMenu(CsMenu csMenu) throws Exception {
        return menuClient.addCsMenu(csMenu);
    }

    public Integer modifyCsMenu(CsMenu csMenu) throws Exception {
        return menuClient.modifyCsMenu(csMenu);
    }

    public Integer deleteCsMenuById(Long id) throws Exception {
        return menuClient.deleteCsMenuById(id);
    }

    public Page<CsMenu> queryCsMenuPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = menuClient.getCsMenuCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CsMenu> csMenuList = menuClient.getCsMenuListByMap(param);
        page.setRows(csMenuList);
        return page;
    }

    public List<CsMenu> getMenuListAll(List<String> authoritiesList, List<String> ids){
        return menuClient.getMenuListAll(authoritiesList, ids);
    }

}
